FROM docker-config-engine-buster

ARG docker_container_name
COPY ["base_image_files/rsyslog.conf", "/etc/rsyslog.conf"]
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install libboost-atomic1.71.0

COPY \
{% for deb in docker_saiserver_clounix_debs.split(' ') -%}
debs/{{ deb }}{{' '}}
{%- endfor -%}
debs/

RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; } ; \
{% for deb in docker_saiserver_clounix_debs.split(' ') -%}
dpkg_apt debs/{{ deb }}{{'; '}}
{%- endfor %}

## TODO: add kmod into Depends
RUN apt-get install -yf kmod \
# Install IPython, jupyter-console packages
        jupyter-console      \
        jupyter-client

COPY ["files/dsserve", "start.sh", "/usr/bin/"]
COPY ["clx_diag", "/usr/bin/"]
COPY ["warm-verifier", "/usr/bin/"]
RUN chmod +x  /usr/bin/clx_diag /usr/bin/warm-verifier /usr/bin/dsserve

COPY ["base_image_files", "/etc/clounix"]
COPY ["base_image_files/port_config.ini", "/etc/sai/portmap.ini"]
COPY ["profile.ini", "/etc/sai/"]

COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]

# IPython kernel config
COPY ["ipython_config.json", "/etc/ipython/"]

# Install IPython Cling Kernel
#{%- if INCLUDE_CLING_KERNEL == "yes" %}
#COPY ["install_clingkernel.sh", "/usr/bin/"]
#COPY ["cling-0.9-buster.tar", "/opt/"]
#RUN /usr/bin/install_clingkernel.sh

RUN apt-get install -y build-essential      \
                       libc-dev             \
                       libc6-dev-i386

ENV CLING_OPTS "-I/usr/include/sai/ \
                -I/usr/include/clounix/ \
                -I/usr/include/clx_system/clx_sdk/include \
                -I/usr/include/clx_system/clx_sdk/include/cdb \
                -I/usr/include/clx_system/clx_sdk/include/osal \
                -I/usr/include/clx_system/clx_sdk/src/inc \
                -DCLX_EN_HOST_64_BIT_LITTLE_ENDIAN \
                -DCLX_EN_LITTLE_ENDIAN \
                -DCLX_EN_COMPILER_SUPPORT_LONG_LONG \
                -DCLX_LINUX_USER_MODE \
                -DCLX_SDK \
                -DCLX_EN_NETIF \
                -DCLX_EN_64BIT_ADDR "
#{%- endif %}

## Clean up
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs

ENTRYPOINT ["/usr/local/bin/supervisord"]
